# 信息
from source import setup, tools
from .. import constants as C
import pygame
from . import coin

pygame.font.init()


class Info:
    def __init__(self, state, game_info):
        self.state = state
        self.game_info = game_info
        self.create_state_lables()
        self.create_info_lables()
        self.flash_coin = coin.FlashingCoin()

    def create_state_lables(self):
        self.start_lables = []
        if self.state == 'main_menu':
            self.start_lables.append((self.create_lables('1 PLAYER GAME'), (272, 360)))
            self.start_lables.append((self.create_lables('2 PLAYER GAME'), (272, 405)))
            self.start_lables.append((self.create_lables('TOP - '), (290, 465)))
            self.start_lables.append((self.create_lables('000000'), (400, 465)))
        if self.state == 'load_screen':
            self.start_lables.append((self.create_lables('WORLD'), (280, 200)))
            self.start_lables.append((self.create_lables('1 - 1'), (430, 200)))
            self.start_lables.append((self.create_lables('x  {}'.format(self.game_info['lives'])), (380, 280)))
            self.player_image = tools.get_image(setup.GRAPHICS['mario_bros'], 178, 32, 12, 16, (0, 0, 0),
                                                C.PLAYER_MULTI)
        if self.state == 'game_over':
            self.start_lables.append((self.create_lables('GAME OVER'), (280, 300)))

    def create_info_lables(self):
        self.info_lables = []
        self.info_lables.append((self.create_lables('MARIO'), (75, 30)))
        self.info_lables.append((self.create_lables('WORLD'), (450, 30)))
        self.info_lables.append((self.create_lables('TIME'), (625, 30)))
        self.info_lables.append((self.create_lables('000000'), (75, 55)))
        self.info_lables.append((self.create_lables('x00'), (300, 55)))
        self.info_lables.append((self.create_lables('1 - 1'), (480, 55)))

    def create_lables(self, lable, size=40, width_scale=1.25, height_scale=1):
        font = pygame.font.SysFont(C.FONT, size)
        lable_image = font.render(lable, 1, (255, 255, 255))
        rect = lable_image.get_rect()
        lable_image = pygame.transform.scale(lable_image, (
            int(rect.width * width_scale),
            int(rect.height * height_scale)
        ))
        return lable_image

    def update(self):
        self.flash_coin.update()

    def draw(self, surface):
        for lable in self.start_lables:
            surface.blit(lable[0], lable[1])
        for lable in self.info_lables:
            surface.blit(lable[0], lable[1])
        surface.blit(self.flash_coin.image, self.flash_coin.rect)
        if self.state == 'load_screen':
            surface.blit(self.player_image, (300, 270))
